//
//  LeftViewController.m
//  SlideViewTest
//
//  Created by Nancy on 13-7-11.
//  Copyright (c) 2013年 Nancy. All rights reserved.
//

#import "LeftViewController.h"
#import "Left_1_ViewController.h"
#import "model.h"

@interface LeftViewController ()

@end

@implementation LeftViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.title = @"左侧边栏";
        //self.view.backgroundColor = [UIColor whiteColor];
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    _btnArr=[[NSMutableArray alloc] init];
    _imgArr=[NSArray arrayWithObjects:@"z1@2x.png",@"z3@2x.png",@"z2@2x.png",@"z9@2x.png",@"z4@2x.png",nil];
    
    self.view.backgroundColor=[UIColor colorWithRed:207.0/255.0 green:227.0/255.0 blue:255.0/255.0 alpha:1];
    /*
    比较懒, 就没有去想这个demo的逻辑
     
     只在左侧边栏中做了返回主界面的处理,其他的类都是只返回到对应的侧边栏.
     大家如果有兴趣的话可以自己去测试 IIViewDeckController.h 这个类中的方法
     
     */
    
    
#pragma mark - 五个模块
    for (int i=0; i<5; i++) {
        UIButton *button=[[UIButton alloc] initWithFrame:CGRectMake(40,45+(100+25)*i,100,100)];
        switch (i) {
            case 0:{
                [button setBackgroundImage:[UIImage imageNamed:@"z1@2x.png"] forState:UIControlStateNormal];
                [button addTarget:self action:@selector(btnAct1:) forControlEvents:UIControlEventTouchUpInside];
            }
                break;
            case 1:{
                [button setBackgroundImage:[UIImage imageNamed:@"z3@2x.png"] forState:UIControlStateNormal];
                [button addTarget:self action:@selector(btnAct2:) forControlEvents:UIControlEventTouchUpInside];
            }
                break;
            case 2:{
                [button setBackgroundImage:[UIImage imageNamed:@"z2@2x.png"] forState:UIControlStateNormal];
                [button addTarget:self action:@selector(btnAct3:) forControlEvents:UIControlEventTouchUpInside];
            }
                break;
            case 3:{
                [button setBackgroundImage:[UIImage imageNamed:@"z9@2x.png"] forState:UIControlStateNormal];
                [button addTarget:self action:@selector(btnAct4:) forControlEvents:UIControlEventTouchUpInside];
            }
                break;
            case 4:{
                [button setBackgroundImage:[UIImage imageNamed:@"z4@2x.png"] forState:UIControlStateNormal];
                [button addTarget:self action:@selector(btnAct5:) forControlEvents:UIControlEventTouchUpInside];
            }
                break;
            default:
                break;
        }
        
        button.tag=100+i;
        [_btnArr addObject:button];
        
        [self.view addSubview:button];
    }
    

//    model *mode=[model shareModel];
//    self.tableView=[[UITableView alloc] initWithFrame:CGRectMake(0, 20, self.view.bounds.size.width, mode.row*50) style:UITableViewStylePlain];
//    self.tableView.dataSource=self;
//    self.tableView.delegate=self;
//    //self.tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
//    [self.view addSubview:self.tableView];
    
}

#pragma mark - 侧边栏按钮动作
- (void)btnAct1:(UIButton *)button
{
    [button setBackgroundImage:[UIImage imageNamed:@"z5@2x.png"] forState:UIControlStateNormal];
    for (UIButton *btn in _btnArr) {
        if (btn.tag!=button.tag) {
            [btn setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@",[_imgArr objectAtIndex:btn.tag-100]]] forState:UIControlStateNormal];
        }
    }
}

- (void)btnAct2:(UIButton *)button
{
    model *mod=[model shareModel];
    mod.searchSelect=NO;
    
    [self goToSubViewLeft:nil];
    
    [button setBackgroundImage:[UIImage imageNamed:@"z7@2x.png"] forState:UIControlStateNormal];
    for (UIButton *btn in _btnArr) {
        if (btn.tag!=button.tag) {
            [btn setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@",[_imgArr objectAtIndex:btn.tag-100]]] forState:UIControlStateNormal];
        }
    }
}

- (void)btnAct3:(UIButton *)button
{
    model *mod=[model shareModel];
    mod.searchSelect=YES;
    
    [self goToSubViewLeft:nil];
    
    [button setBackgroundImage:[UIImage imageNamed:@"z6@2x.png"] forState:UIControlStateNormal];
    for (UIButton *btn in _btnArr) {
        if (btn.tag!=button.tag) {
            [btn setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@",[_imgArr objectAtIndex:btn.tag-100]]] forState:UIControlStateNormal];
        }
    }
}

- (void)btnAct4:(UIButton *)button
{
    [button setBackgroundImage:[UIImage imageNamed:@"z10@2x.png"] forState:UIControlStateNormal];
    for (UIButton *btn in _btnArr) {
        if (btn.tag!=button.tag) {
            [btn setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@",[_imgArr objectAtIndex:btn.tag-100]]] forState:UIControlStateNormal];
        }
    }
}

- (void)btnAct5:(UIButton *)button
{
    [button setBackgroundImage:[UIImage imageNamed:@"z8@2x.png"] forState:UIControlStateNormal];
    for (UIButton *btn in _btnArr) {
        if (btn.tag!=button.tag) {
            [btn setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@",[_imgArr objectAtIndex:btn.tag-100]]] forState:UIControlStateNormal];
        }
    }
}

#pragma mark -

-(void)goToSubViewLeft:(id)sender
{
    [self.viewDeckController closeLeftViewBouncing:^(IIViewDeckController *controller) {
        
        searchViewController *search=[model shareSearch];
        
        model *mod=[model shareModel];
        if (!mod.searchSelect) {
            search.selectedView.center=CGPointMake(mod.x1, mod.y);
        } else {
            search.selectedView.center=CGPointMake(mod.x2, mod.y);
        }
        
        
        self.viewDeckController.centerController = [[UINavigationController alloc] initWithRootViewController:search];
        
        self.view.userInteractionEnabled = YES;
    }];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
